package com.tgy.admin.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.tgy.admin.Service.AdminCommentService;
import com.tgy.page.PageQuery;
import com.tgy.pojo.BlogComment;
import com.tgy.pojo.BlogUser;
import com.tgy.result.GraceJSONResult;
import com.tgy.result.LayuiTableResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author tianguiyin
 * @version 1.0
 * @date 2022/6/21 21:01
 */
@Validated
@Api(value = "评论控制器", tags = {"评论管理"})
@RestController
@RequestMapping("/admin/comment")
public class AdminCommentController {

    @Resource
    private AdminCommentService adminCommentService;

    @ApiOperation("获取评论列表")
    @SaCheckPermission("blogComment:query")
    @GetMapping("getBlogCommentList")
    public LayuiTableResult getBlogCommentList(BlogComment bo, PageQuery pageQuery){
        return adminCommentService.getBlogCommentList(bo,pageQuery);
    }

    @ApiOperation("修改博客用户状态")
    @SaCheckPermission("blogComment:update")
    @PostMapping("updateStatus")
    public GraceJSONResult updateStatus(BlogUser bo){
        return adminCommentService.updateStatus(bo.getId(),bo.getStatus());
    }

    @ApiOperation("添加评论")
    @SaCheckPermission("blogComment:add")
    @PostMapping("addBlogComment")
    public GraceJSONResult addBlogComment(BlogComment bo){
        return adminCommentService.addBlogComment(bo);
    }

    @ApiOperation("修改评论")
    @SaCheckPermission("blogComment:update")
    @PostMapping("updateBlogComment")
    public GraceJSONResult updateBlogComment(BlogComment bo){
        return adminCommentService.updateBlogComment(bo);
    }

    @ApiOperation("删除评论")
    @SaCheckPermission("blogComment:del")
    @PostMapping("delBlogComment")
    // @PostMapping("delBlogAdminComment/{id}")
    public GraceJSONResult delBlogComment(@ApiParam("ID必须传入") String id){
        return adminCommentService.delBlogComment(id);
    }

    @ApiOperation("批量删除评论")
    @SaCheckPermission("blogComment:del")
    @PostMapping("delBlogCommentIds")
    public GraceJSONResult delBlogCommentIds(@ApiParam("ids必须传入") String ids){
        List<String> list = new ArrayList<>(Arrays.asList(ids.split(",")));
        return adminCommentService.delBlogCommentIds(list);
    }

    @ApiOperation("根据ID查询评论")
    @SaCheckPermission
    @PostMapping("getBlogCommentById")
    public GraceJSONResult getBlogCommentById(@ApiParam("ID必须传入") String id){
        return adminCommentService.getBlogCommentById(id);
    }


    @ApiOperation("根据ID查询评论")
    @SaCheckPermission
    @GetMapping("getBlogCommentListNotPage")
    public GraceJSONResult getBlogCommentListNotPage(String articleId){
        return GraceJSONResult.ok(adminCommentService.getBlogCommentById(articleId));
    }


}
